package com.one.blocks.mvc.enums;

import com.one.blocks.common.enums.CodeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author linfuxin Created on 2022-02-14 10:39:05
 */
@Getter
@AllArgsConstructor
public enum BatchStrategyEnum implements CodeEnum {

    /**
     * 异常跳过，已入库数据不回滚
     */
    IGNORE(0),

    /**
     * 异常中断，已入库数据不回滚
     */
    BREAK_OFF(1),

    /**
     * 异常回滚，已入库数据回滚
     */
    ROLLBACK(2),
    ;

    private final int code;

    public static BatchStrategyEnum getInstance(Integer code) {
        if (code == null) {
            return ROLLBACK;
        }
        for (BatchStrategyEnum value : values()) {
            if (value.code == code) {
                return value;
            }
        }
        return null;
    }
}
